﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace MailBox
{
    /// <summary>
    /// Summary description for DownloadFile
    /// </summary>
    public class DownloadFile : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string file = context.Request.QueryString["file"];
                string filepath = context.Server.MapPath(file);
                System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                response.ClearContent();
                response.Clear();
                response.ContentType = "text/plain";
                response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filepath) + ";");
                response.TransmitFile(filepath);
                response.Flush();
                response.End();
            }
            catch //(Exception ex)
            { context.Response.Redirect("Error.aspx?err=301"); context.Response.Flush(); }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}